package com.ophiux.utils.encrypt;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * @desc：base64编码<br>
 * @author: hhl<br>
 * @date: 2021年9月3日 上午9:38:30<br>
 */
public class Base64Coding {

	/**
	 * 
	 * base64解码<br>
	 * @param content
	 * @return
	 */
	@SuppressWarnings("restriction")
	public static String base64Decoding(String content) {
		byte[] b = null;
		String result = null;
		if (content != null) {
			BASE64Decoder decoder = new BASE64Decoder();
			try {
				b = decoder.decodeBuffer(content);
				result = new String(b);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return result;
	}

	public static byte[] base64DecodingToByte(String content) {
		byte[] result = null;
		if (content != null) {
			BASE64Decoder decoder = new BASE64Decoder();
			try {
				result = decoder.decodeBuffer(content);

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return result;
	}

	/**
	 * 
	 * Description:base64编码 <br>
	 * @param content
	 * @return
	 */
	@SuppressWarnings("restriction")
	public static String base64Encoding(byte[] content) {

		String result = null;
		if (content != null) {

			BASE64Encoder encoder = new BASE64Encoder();
			result = encoder.encode(content);
		}
		return result;
	}

}
